package com.adobe.serialization.json
{

	/**
	 * This class provides encoding and decoding of the JSON format.
	 *
	 * Example usage:
	 * <code>
	 * 		// create a JSON string from an internal object
	 * 		JSON.encode( myObject );
	 *
	 *		// read a JSON string into an internal object
	 *		var myObject:Object = JSON.decode( jsonString );
	 *	</code>
	 */
	public class JSON
	{


		/**
		 * Encodes a object into a JSON string.
		 *
		 * @param o The object to create a JSON string for
		 * @return the JSON string representing o
		 */
		public static function encode(o:Object):String
		{

			var encoder:JSONEncoder=new JSONEncoder(o);
			return encoder.getString();

		}

		/**
		 * Decodes a JSON string into a native object.
		 *
		 * @param s The JSON string representing the object
		 * @return A native object as specified by s
		 * @throw JSONParseError
		 */
		public static function decode(s:String):*
		{
			try
			{
				var decoder:JSONDecoder=new JSONDecoder(s);
			}
			catch (e:Error)
			{
				trace("" + e);
				return null;
			}
			return decoder.getValue();
		}
	}

}
